package com.huanglj.himalaya.data.API;

import com.ximalaya.ting.android.opensdk.constants.DTransferConstants;
import com.ximalaya.ting.android.opensdk.datatrasfer.CommonRequest;
import com.ximalaya.ting.android.opensdk.datatrasfer.IDataCallBack;
import com.ximalaya.ting.android.opensdk.model.album.SearchAlbumList;
import com.ximalaya.ting.android.opensdk.model.word.HotWordList;
import com.ximalaya.ting.android.opensdk.model.word.SuggestWords;

import java.util.HashMap;
import java.util.Map;

import static com.huanglj.himalaya.utils.Constants.HOT_TOP;
import static com.huanglj.himalaya.utils.Constants.SUGGEST_SIZE;

public class XimalayaAPI {

    private XimalayaAPI(){

    }
    private static XimalayaAPI sAPI = null;

    public static XimalayaAPI getInstance(){
        if (sAPI == null){
            synchronized (XimalayaAPI.class){
                if (sAPI == null) {
                    sAPI = new XimalayaAPI();
                }
            }
        }
        return sAPI;
    }

    /**
     * 获取推荐专辑的关键字搜素结果
     * @param keyword
     */
    public void searchByKeyWord( IDataCallBack<SearchAlbumList> dataCallBack,String keyword,int page) {
        Map<String, String> map = new HashMap<String, String>();
        map.put(DTransferConstants.SEARCH_KEY, keyword);
        map.put(DTransferConstants.CATEGORY_ID,"");
        map.put(DTransferConstants.PAGE, page+"");
        CommonRequest.getSearchedAlbums(map,dataCallBack);
    }

    /**
     * 根据热词搜索
     * @param callBack
     */
    public void searchByHotWord(IDataCallBack<HotWordList> callBack) {
        Map<String, String> map = new HashMap<String, String>();
        map.put(DTransferConstants.TOP, HOT_TOP+"");
        CommonRequest.getHotWords(map, callBack);
    }

    /**
     * 根据联想词搜索
     * @param keyword
     * @param callBack
     */
    public void getByRecommend(String keyword, IDataCallBack<SuggestWords> callBack) {
        Map<String, String> map = new HashMap<String, String>();
        map.put(DTransferConstants.SEARCH_KEY, keyword);
        CommonRequest.getInstanse().setDefaultPagesize(SUGGEST_SIZE);
        CommonRequest.getSuggestWord(map, callBack);
    }
}
